function openWin(name,url,param){
    var p = {}
    if(isDefine(param)){
        p=param
    }
    var reload = true;
    if(name =='index'){
        reload = false;
    }
    api.openWin({
        name: name,
        url: url,
        pageParam:p,
        reload:reload,
    });
}
//打开网页
 function openApp(url,id,type) {
    console.log(url);
    console.log(id);
    console.log(type);
    if(type =="0"){
         api.openApp({
                androidPkg : 'android.intent.action.VIEW',
                mimeType : 'text/html',
                uri : url,
                iosUrl:url,
        }, function(ret, err) {

        });
    }else{
        if(type == 1){
            goWare(id);
        }else if(type == 2){
            var p ={
                sdid:id
            }
            openWin('shop','shop.html',p);
        }else if(type == 3){
            openWin('community_details','community_details.html',{id:id});
        }
        
    }
}
//打开网页
 function openWeb(url) {
         api.openApp({
            androidPkg : 'android.intent.action.VIEW',
            mimeType : 'text/html',
            uri : url,
            iosUrl:url,
        }, function(ret, err) {

        });
}

//返回上一级
function historyBack(){
    api.historyBack({
    },function(ret,err){
        if (!ret.status) {
            api.closeWin();
        }
    });
}
//判断是否登录
function isLogin(){
	if($api.getStorage('token') != null && $api.getStorage('token') != "undefined"){
        return true;
    }else{
        var msg = "请登录";
        if(cnen==2){
            msg = "Please login";
        }
        pop.notice(msg,1,function(res){
            goLogin('index');
        });
        return false;
    }
}



//跳转个人中心
function member(){
    // goLogin('index');
    // return;
    if(isLogin()){
        if(user_type==2){
            openWin('shop_member','shop_member.html');
        }else{
            openWin('member','member.html');
        }

    }else{
        //goLogin('index');
    }
}
//跳转购物车
function shoppingCart(){
    if(isLogin()){
        openWin('shoppingCart','shoppingCart.html');
    }else{
        //goLogin('index');
    }
}

function goLogin(pageName){
    var p={html:pageName}
    openWin('login','login.html',p);
}

function goWare(id){
    var p={id:id}
    openWin('ware','ware.html',p);
}

function openClass(id){
    var p={id:id}
    openWin('classify','classify.html',p);
}

function openWarePage(index){
    var p = {type:index}
  openWin('index_warePage','index_warePage.html',p);
}


function goOrder(type){
    openWin('order','order.html',{type:type});
}


//跳转消息
function gomsg(){
    // goLogin('index');
    // return;
    if(isLogin()){
        openWin('message','message.html');
    }else{
        //goLogin('index');
    }
}

//跳转收藏
function gosc(){
    // goLogin('index');
    // return;
    if(isLogin()){
      openWin('member_favorite','member_favorite.html');
    }else{
        //goLogin('index');
    }
}
//微信分享
function wxpyqFX(param){
    var wx = api.require('wx');
    wx.shareWebpage(param, function(ret, err) {
        if (ret.status) {
            pop.notice('分享成功');
        } else {
            pop.notice(err.code);
        }
    });
}

function WeiBofx(param){
    var shareApi = api.require('shareSDKPlus');
    shareApi.authorize({
    "platform": $sharesdk.PlatformID.SinaWeibo
    },function(ret, err){
    var state = ret.state;
    switch(state)
    {
        case $sharesdk.ResponseState.Success://1
            api.toast({
                msg: "授权成功",
                location: 'middle'
            });
        break;
        case $sharesdk.ResponseState.Fail://2
            api.toast({
                msg: "授权失败",
                location: 'middle'
            });
        break;
        case $sharesdk.ResponseState.Cancel://3
            api.toast({
                msg: "取消授权",
                location: 'middle'
        });
        break;
       default:
    }     
    });
    // shareApi.shareContent({
    //     "platform": $sharesdk.PlatformID.SinaWeibo,"shareParams": param
    // },function(ret, err){
    //     var state = ret.state;
    //     console.log(state);
    //     switch(state)
    //     {
    //         case $sharesdk.ResponseState.Success://1
    //             pop.notice('分享成功');
    //         break;
    //         case $sharesdk.ResponseState.Fail://2
    //             pop.notice('分享失败');
    //         break;
    //         case $sharesdk.ResponseState.Cancel://3
    //             pop.notice('取消');
    //         break;
    //        default:
    //     }     
    // });
}

function qqfx(param){
    var qq = api.require('QQPlus');
    qq.shareNews(param,function(ret,err){
      if (ret.status){
        pop.notice('分享成功');
      } else {
        pop.notice('分享失败');
      }
    });
}

function weibo_authorize(param){
    var weiboPlus= api.require('weiboPlus');
        weiboPlus.shareWebPage(param, function(ret, err) {
        if (ret.status) {
            pop.notice('分享成功');
        }
    });
}

function fackBookFX(param){
    console.log('打开Facebook');
    var facebook = api.require('facebook');
    // facebook.isInstalled(function(ret, err) {
    //     if (ret.installed) {
    //         alert("当前设备已安装facebook客户端");
    //     } else {
    //         alert('当前设备未安装facebook客户端');
    //     }
    // });
    facebook.shareLinked(param, function(ret, err){
        console.log(JSON.stringify(ret));
         if(ret.status) {
            pop.notice('分享成功');
         } else {
            pop.notice(err.code);
         }
   });
    // var redirectUrl =ajaxUrl.cnurl+param.url;
    // var shareUrl = "http://baidu.com";
    // var url = "https://www.facebook.com/dialog/share?display=popup&app_id=2098929150132025&href="+redirectUrl+"&redirect_uri="+redirectUrl;
    // openApp(url,0,0);
}

